var taskData=[], teamName=[], series=[];
// var Highcharts = require('highcharts');
function queryTeamSum(st,et) {

    var data = {
		userId: avalon.vmodels.root.user.id,
		userToken:avalon.vmodels.root.user.token,
        startTime: '',
		endTime: ''
    }
	if (st && et){
		data.startTime = st;
		data.endTime = et
	}

    //查询支队所有任务
    $.ajax({
        url:server.teamTask,
        type:'get',
        dataType:'json',
        data: data
    })
        .done(function (res) {
            var data = res.values;
            if (res.status == '9200'){
                $('#teamTaskTable').bootstrapTable({});

                setTimeout(function () {
                    $('#teamTaskTable').bootstrapTable('load', data);
                    $('#teamTaskTable').bootstrapTable('selectPage', 1);
                },100)

                taskData = data;//所有支队的数据

                //获取所有支队名字
                taskData.map(function (item) {

                    var totalArray = []
                    var finishArray = []
                    teamName.push(item.groupName)
                    totalArray.push(item.taskCount)
                    finishArray.push(item.taskFinishCount)

                    series.push({
                        name : '任务总数',
                        data : totalArray
                    },{
                        name : '完成数量',
                        data : finishArray
                    })

                })

            }else {
                $('#teamTaskTable').bootstrapTable({})
            }
        })
        .fail(function (res) {
            _alert('网络错误，请稍后重试');
        })
}


// 查询总任务数目
function queryTotalSum(st,et) {

    var data = {
        userId: avalon.vmodels.root.user.id,
        userToken:avalon.vmodels.root.user.token,
        startTime: '',
        endTime: ''
    }
    if (st && et){
        data.startTime = st;
        data.endTime = et
    }

    //查询所有任务
    $.ajax({
        url:server.totalTask,
        type:'get',
        dataType:'json',
        data: data
    })
        .done(function (res) {
            if (res.status == '9200'){
            	query.total.display = true;
                query.total.count = res.count;
            }else {
                query.total.display = false;
            }
        })
        .fail(function (res) {
            _alert('网络错误，请稍后重试');
        })
}


var server = require('api');
var _alert = require('alert');
var query = avalon.define({
	$id : 'query',

	total:{
		startTime:'',
		endTime:'',
		count:'',
        display:false
	},

	team:{
		startTime:'',
		endTime:''
	},

    queryTotal:function () {
		var _st = query.total.startTime;
		var _et = query.total.endTime;
        queryTotalSum(_st, _et);
    },

    queryTeam:function () {
		var _st = query.team.startTime;
		var _et = query.team.endTime;
        queryTeamSum(_st, _et);
    },

	// handle block css

    btnBlockTotal: function () {
	    $('#btnareatotal').css('display','');
        $('#btnareabranch').css('display','none');

        $('#angletotal').css('display','');
        $('#anglebranch').css('display','none');
    },

    btnBlockBranch: function () {

        $('#btnareabranch').css('display','block');
        $('#btnareatotal').css('display','none');

        $('#angletotal').css('display','none');
        $('#anglebranch').css('display','');
    },

	init : function(){
		avalon.log('综合查询init' + _.now());

		setTimeout(function () {

			$(function () {
                queryTeamSum();
            })

        },100)
	}
})




module.exports = query;